import caozuo from "../api/caozuo";
import globalData from '@/plugins/utils/global'
const self = globalData.self

// 使用示例
export function updateSelf(data) {
    Object.assign(self, data) // 合并数据
}

export const orderCaozuo = {
    add: async (order) => {
        const obj = {
            userId: self.id,
            type: 2,
            label: `${self.nickName}创建订单, 订单编号: ${order.orderNo}, 当前订单状态: 待接单`,
            createTime: new Date().getTime()
        }
        await caozuo.add(obj)
    },
    update: async (order) => {
        const obj = {
            userId: self.id,
            type: 2,
            label: `${self.nickName}更新订单, 订单编号: ${order.orderNo}, 当前订单状态: ${order.orderStatus === 2 ? '已接单' : order.orderStatus === 3 ? '待确认' : order.orderStatus === 4 ? '已完成' : order.orderStatus === 0 ? '已取消' : '待接单'}`,
            createTime: new Date().getTime()
        }
        await caozuo.add(obj)
    },
}

export const userCaozuo = {
    add: async (user) => {
        const obj = {
            userId: self.id,
            type: 1,
            label: `${self.nickName}添加用户 ${user.nickName}`,
            createTime: new Date().getTime()
        }
        await caozuo.add(obj)
    },
    update: async (user) => {
        const obj = {
            userId: self.id,
            type: 1,
            label: `${self.nickName}更新用户 ${user.nickName} 信息`,
            createTime: new Date().getTime()
        }
        await caozuo.add(obj)
    },
    login: async () => {
        console.log(self);

        const obj = {
            userId: self.id,
            type: 1,
            label: `${self.nickName}登录系统`,
            createTime: new Date().getTime()
        }
        const res = await caozuo.add(obj)
        console.log('操作-> ', res);

    },
}